package com.hbzhit.common.entity;

import cn.afterturn.easypoi.excel.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableField;
import com.hbzhit.common.utils.CacheUtils;
import com.hbzhit.modules.act.dto.TaskDTO;
import com.hbzhit.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.List;

/**
 * 基础流程实体类
 * 定义各个流程实体对象的通用字段
 * @author DING
 */
@Getter
@Setter
@ApiModel("基础流程实体类")
public class ProcessEntity extends BaseEntity {
    @ApiModelProperty("流程编号")
    @Excel(name = "流程编号", width = 30, orderNum = "0")
    private String processNo;

    @ApiModelProperty("流程ID")
    private Long processId;

    @ApiModelProperty("流程状态")
    private Integer status;

    @ApiModelProperty("流程状态名称")
    @Excel(name = "流程状态", width = 20, orderNum = "100")
    private String statusName;

    @ApiModelProperty("申请人")
    private Long applicant;

    @ApiModelProperty("申请时间")
    @Excel(name = "申请时间", format = "yyyy-MM-dd HH:mm:ss", width = 30, orderNum = "5")
    private Date applyTime;

    @ApiModelProperty("审核人")
    private Long approver;

    @ApiModelProperty("审核时间")
    @Excel(name = "审核时间", format = "yyyy-MM-dd HH:mm:ss", width = 30, orderNum = "102")
    private Date approvalTime;

    @ApiModelProperty("当前审批任务")
    @TableField(exist = false)
    private TaskDTO task;

    @ApiModelProperty("审批记录")
    @TableField(exist = false)
    private List<TaskDTO> taskList;

    @ApiModelProperty("申请人名称")
    @Excel(name = "申请人", width = 20, orderNum = "1")
    @TableField(exist = false)
    private String applicantName;

    @ApiModelProperty("申请人身份证号码")
    @Excel(name = "身份证号码", width = 30, orderNum = "2")
    @TableField(exist = false)
    private String applicantIdcard;

    @ApiModelProperty("申请人联系方式")
    @Excel(name = "联系方式", width = 30, orderNum = "3")
    @TableField(exist = false)
    private String applicantMobile;

    @ApiModelProperty("申请人所在组织")
    @Excel(name = "所在组织", width = 30, orderNum = "4")
    @TableField(exist = false)
    private String applicantOrgName;

    @ApiModelProperty("申请人对象")
    @TableField(exist = false)
    private SysUserEntity applicantEntity;

    @ApiModelProperty("审核人名称")
    @Excel(name = "审核人", width = 20, orderNum = "101")
    @TableField(exist = false)
    private String approverName;

    public String getApplicantName() {
        return getApplicantEntity().getRealName();
    }

    public String getApplicantIdcard() {
        return getApplicantEntity().getIdcard();
    }

    public String getApplicantMobile() {
        return getApplicantEntity().getMobile();
    }

    public String getApplicantOrgName() {
        return getApplicantEntity().getOrgName();
    }

    public SysUserEntity getApplicantEntity() {
        return CacheUtils.getUserCache(applicant);
    }

    public String getApproverName() {
        return CacheUtils.getUserCache(approver).getRealName();
    }
}
